home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_msql.idb / usr / freeware / msql / include / lite.h.z / lite.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  8.6 KB  |  385 lines

  1.  
  2.  
  3. #include <sys/types.h>
  4. #include <common/portability.h>
  5.  
  6.  
  7.  
  8. typedef    u_char    *U_C_PTR;
  9.  
  10. #undef  YYSTYPE
  11. #define    YYSTYPE    U_C_PTR
  12.  
  13. #define    SYM_NAME_LEN    48
  14. #define    VAL_BUF_LEN    10
  15.  
  16. typedef struct code_s {
  17.     char    op;
  18.     char    *arg;
  19.     u_short    label;
  20.     short    type;
  21.     u_short    line;
  22.     char    file;
  23.     struct code_s *next,
  24.         *prev;
  25. } code_t;
  26.  
  27.  
  28.  
  29. typedef struct _sym {
  30.         char    name[SYM_NAME_LEN],
  31.         valBuf[VAL_BUF_LEN],
  32.                 *val;
  33.         short    type;
  34.     char    array,
  35.         usign;
  36.         int     length,
  37.         source;
  38.         struct _sym *next;
  39. } sym_t;
  40.  
  41.  
  42. typedef struct _funct {
  43.     char    *name;
  44.     code_t    *code;
  45.     sym_t    *params;
  46.     struct     _funct *next;
  47. } funct_t;
  48.  
  49.  
  50. typedef    struct array_s {
  51.     sym_t    *sym;
  52.     struct    array_s *next;
  53. } array_t;
  54.  
  55.  
  56.  
  57. typedef struct stack_s {
  58.     u_short    block;
  59.     short    type;
  60.     sym_t    *sym;
  61.     struct    stack_s *next;
  62. } sstack_t;
  63.  
  64.  
  65. typedef struct plist_s {
  66.         sym_t    *sym;
  67.         struct  plist_s *next;
  68. } plist_t;
  69.  
  70.  
  71. typedef struct efunct_s {
  72.         char    *name;
  73.         void    (*funct) ();
  74.     char    *functName;
  75.         int        numParams;
  76.         int     paramTypes[20];
  77. } efunct_t;
  78.  
  79.  
  80.  
  81. typedef struct fbucket_s {
  82.         efunct_t                *funct;
  83.         struct fbucket_s        *next;
  84. } fbucket_t;
  85.  
  86.  
  87. typedef struct lstack_s {
  88.     int    label;
  89.     struct    lstack_s    *next;
  90. } lstack_t;
  91.  
  92.  
  93. typedef struct type_s {
  94.     char    *name;
  95.     int    length;
  96.     int    (*pack)();
  97.     int    (*unpack)();
  98.     int    (*read)();
  99.     int    (*write)();
  100.     int    (*compare)();
  101.     int    (*math)();
  102.     int    (*check)();
  103. } type_t;
  104.  
  105.  
  106.  
  107. #define    OP_CALL        1
  108. #define OP_PUSH        2
  109. #define OP_CMP        3
  110. #define OP_JMP        4
  111. #define OP_JMP_FALSE    5
  112. #define OP_JMP_BACK    6
  113. #define OP_LABEL    7
  114. #define OP_STORE    8
  115. #define OP_A_STORE    9
  116. #define OP_DEREF    10
  117. #define OP_ALU        11
  118. #define OP_BLOCK_IN    12
  119. #define OP_BLOCK_OUT    13
  120. #define OP_EXIT        14
  121. #define OP_ECHO        15
  122. #define OP_CAST        16
  123. #define OP_COUNT    17
  124. #define OP_PUSHRET    18
  125. #define OP_RETURN    19
  126.  
  127. #define    OP_ADD        100
  128. #define OP_SUB        101
  129. #define OP_MUL        102
  130. #define OP_DIV        103
  131. #define OP_AND        105
  132. #define OP_OR        106
  133. #define OP_MOD        107
  134.  
  135. #define SCALAR        1
  136. #define ARRAY        2
  137. #define    VARIABLE    3
  138.  
  139. #define    TYPE_REAL    0
  140. #define    TYPE_INT    1
  141. #define    TYPE_CHAR    2
  142. #define    TYPE_UINT    3
  143.  
  144.  
  145. #define    P_TEXT        1
  146. #define    P_INT        2
  147. #define P_ARRAY        3
  148.  
  149.  
  150. #define    SRC_POST    1
  151. #define SRC_IMPORT    2
  152. #define SRC_GET        3
  153. #define SRC_SECURE    SRC_IMPORT
  154.  
  155. #define SYM_HASH_SIZE   128
  156.  
  157.  
  158. #define    LITE_BRK    ""
  159.  
  160. /*
  161. ** Pre declarations
  162. */
  163.  
  164. #if defined(__STDC__) || defined(__cplusplus)
  165. #  define __ANSI_PROTO(x)       x
  166. #else
  167. #  define __ANSI_PROTO(x)       ()
  168. #endif
  169.  
  170.  
  171.  
  172. /* Lexer / Parser */
  173.  
  174. int    yylex();
  175. int    yyparse();
  176. void    yyerror __ANSI_PROTO((char *));
  177. void    parseError __ANSI_PROTO((char *));
  178. void    runError __ANSI_PROTO((char *));
  179. void     lexInitScanner __ANSI_PROTO((u_char *));
  180. void     sendFooter ();
  181.  
  182.  
  183. /* Symbol table routines */
  184.  
  185. int symCheckSymbol __ANSI_PROTO((char *));
  186. int symGetNumArrayElements __ANSI_PROTO((sym_t *));
  187. int symSetArray __ANSI_PROTO((char *, sym_t *));
  188.  
  189. char *expandText __ANSI_PROTO((char *));
  190. char *symUnpackSymbol __ANSI_PROTO((sym_t *));
  191.  
  192. sym_t *createArray();
  193. sym_t *createArrayLiteral();
  194. sym_t *createCharSymbol __ANSI_PROTO((char *));
  195. sym_t *createIntSymbol __ANSI_PROTO((int));
  196. sym_t *createRealSymbol __ANSI_PROTO((double));
  197. sym_t *createUintSymbol __ANSI_PROTO((int));
  198. sym_t *symCreateLiteral __ANSI_PROTO((char *, int));
  199. sym_t *symCreateMacroLiteral __ANSI_PROTO((char *));
  200. sym_t *symCreateSymbol __ANSI_PROTO((char *, int, int));
  201. sym_t *symGetArrayElement __ANSI_PROTO((sym_t *, int));
  202. sym_t *symGetEnvironVariable __ANSI_PROTO((char *));
  203. sym_t *symGetMacro __ANSI_PROTO((char *));
  204. sym_t *symGetSymbol __ANSI_PROTO((char *));
  205. sym_t *symdup __ANSI_PROTO((sym_t *));
  206.  
  207. void initSymbolTables();
  208. void symAddArrayElement __ANSI_PROTO((char *));
  209. void symClearArray __ANSI_PROTO((sym_t *));
  210. void symCreateArrayGlobal __ANSI_PROTO((char *,char **,int));
  211. void symCreateCharGlobal __ANSI_PROTO((char *,char *));
  212. void symCreateCharMacro __ANSI_PROTO((char *,char *));
  213. void symCreateIntGlobal __ANSI_PROTO((char *,int));
  214. void symCreateIntMacro __ANSI_PROTO((char *,int));
  215. void symCreateRealGlobal __ANSI_PROTO((char *,double));
  216. void symCreateRealMacro __ANSI_PROTO((char *,double));
  217. void symFreeSymbol __ANSI_PROTO((sym_t *));
  218. void symFreeSymbolData __ANSI_PROTO((sym_t *));
  219. void symSetArrayElement __ANSI_PROTO((sym_t *, int, sym_t *));
  220. void symSetValue __ANSI_PROTO((sym_t *, sym_t *));
  221. void symStackIn();
  222. void symStackOut();
  223. void symStoreSymbol __ANSI_PROTO((sym_t **, sym_t *));
  224. void symTypeCast __ANSI_PROTO((sym_t *,int));
  225.  
  226. array_t *symArrayDup __ANSI_PROTO((sym_t *));
  227.  
  228.  
  229. /* Code generation routines */
  230.  
  231. int     addFunction __ANSI_PROTO((char *));
  232. int     addParam __ANSI_PROTO((char *, char *));
  233. int     codePopBreak();
  234. int     codePopContinue();
  235. int     codePopLabel();
  236. int     popBreak ();
  237. int     popContinue ();
  238. int     popLabel ();
  239.  
  240. void     codeALU __ANSI_PROTO((int));
  241. void     codeArrayStore __ANSI_PROTO((char *));
  242. void     codeBlockIn();
  243. void     codeBlockOut();
  244. void     codeCall __ANSI_PROTO((char *));
  245. void     codeCast __ANSI_PROTO((char *));
  246. void     codeCmp __ANSI_PROTO((int));
  247. void     codeCount();
  248. void     codeDeref __ANSI_PROTO((char *));
  249. void     codeEcho __ANSI_PROTO((char *));
  250. void     codeExit ();
  251. void     codeHtml __ANSI_PROTO((int, int));
  252. void     codeJmp __ANSI_PROTO((int));
  253. void     codeJmpBack __ANSI_PROTO((int));
  254. void     codeJmpFalse __ANSI_PROTO((int));
  255. void     codeLabel __ANSI_PROTO((int));
  256. void     codePush __ANSI_PROTO((char *));
  257. void     codePushBreak __ANSI_PROTO((int));
  258. void     codePushContinue __ANSI_PROTO((int));
  259. void     codePushLabel __ANSI_PROTO((int));
  260. void     codePushRet();
  261. void     codeReturn();
  262. void     codeStore __ANSI_PROTO((char *));
  263. void     dumpCode ();
  264. void     endOfFunction();
  265. void     pushBreak __ANSI_PROTO((int));
  266. void     pushContinue __ANSI_PROTO((int));
  267. void     pushLabel __ANSI_PROTO((int));
  268.  
  269.  
  270. /* Code simulation routines */
  271.  
  272. int    checkNumeric __ANSI_PROTO((char *));
  273. int    getLine();
  274. int    runCode __ANSI_PROTO((char *));
  275. int     simGetLineNum();
  276.  
  277. char *simGetFileName();
  278.  
  279. void    doExit();
  280. void    doBlockIn();
  281. void    doBlockOut();
  282. void    doCall __ANSI_PROTO((code_t *));
  283. void    doEcho __ANSI_PROTO((plist_t *));
  284. void    doPushVar __ANSI_PROTO((code_t *));
  285. void    doPushVal __ANSI_PROTO((code_t *));
  286. void    doPushLiteral __ANSI_PROTO((code_t *));
  287. void    doStore __ANSI_PROTO((code_t *));
  288. void    doArrayStore __ANSI_PROTO((code_t *));
  289. void    doDeref __ANSI_PROTO((code_t *));
  290. void    doALU __ANSI_PROTO((code_t *));
  291. void    doCmp __ANSI_PROTO((code_t *));
  292.  
  293.  
  294.  
  295. /* External interface routines */
  296.  
  297. int    calcHash __ANSI_PROTO((char *));
  298. int    getNumArrayElements __ANSI_PROTO((array_t *));
  299. int     hex2dec __ANSI_PROTO((char *));
  300. int     modLoadModule __ANSI_PROTO((char *));
  301. int     modLoadModuleFunctions __ANSI_PROTO((void *, efunct_t *));
  302. int     oct2dec __ANSI_PROTO((char *));
  303. int    str2int __ANSI_PROTO((char *));
  304.  
  305. char    *deleteObject __ANSI_PROTO((u_int));
  306. char    *fetchObject __ANSI_PROTO((u_int));
  307. char    *getArrayElement __ANSI_PROTO((array_t *, int));
  308. char    *int2str __ANSI_PROTO((int));
  309.  
  310. void    addExterns __ANSI_PROTO((efunct_t *));
  311. void    setReturnValue __ANSI_PROTO((char *, int));
  312. void    setupModules ();
  313.  
  314. sym_t     *createArray();
  315.  
  316. u_int    storeObject __ANSI_PROTO((char *));
  317.  
  318. efunct_t *findExtern __ANSI_PROTO((char *));
  319.  
  320.  
  321. /* Type handling routines */
  322.  
  323. type_t     *typeGetType __ANSI_PROTO((int));
  324. int     typeGetTypeIndex __ANSI_PROTO((char *));
  325.  
  326. sym_t    *createIntSymbol __ANSI_PROTO((int));
  327. sym_t    *createRealSymbol __ANSI_PROTO((double));
  328. sym_t    *createCharSymbol __ANSI_PROTO((char *));
  329.  
  330.  
  331.  
  332. /* lib.c prototypes */
  333. int libLoadLibrary __ANSI_PROTO((char *));
  334. int libWriteLibrary __ANSI_PROTO((char *));
  335.  
  336.  
  337. /* Misc */
  338.  
  339. void checkContentType();
  340. void initStandardModule();
  341. void initMsqlModule();
  342. void initModules();
  343. void setError();
  344. int typeDetermineType __ANSI_PROTO((char*));
  345.  
  346.  
  347. /*
  348. ** Inline definitions
  349. */
  350.  
  351. /* inlined, unaligned, 4-byte copy */
  352. #define bcopy4(s,d) \
  353.       ((((unsigned char *)d)[0] = ((unsigned char *)s)[0]), \
  354.        (((unsigned char *)d)[1] = ((unsigned char *)s)[1]), \
  355.        (((unsigned char *)d)[2] = ((unsigned char *)s)[2]), \
  356.        (((unsigned char *)d)[3] = ((unsigned char *)s)[3]))
  357. /* inlined, unaligned, 8-byte copy */
  358. #define bcopy8(s,d) \
  359.       ((((unsigned char *)d)[0] = ((unsigned char *)s)[0]), \
  360.        (((unsigned char *)d)[1] = ((unsigned char *)s)[1]), \
  361.        (((unsigned char *)d)[2] = ((unsigned char *)s)[2]), \
  362.        (((unsigned char *)d)[3] = ((unsigned char *)s)[3]), \
  363.        (((unsigned char *)d)[4] = ((unsigned char *)s)[4]), \
  364.        (((unsigned char *)d)[5] = ((unsigned char *)s)[5]), \
  365.        (((unsigned char *)d)[6] = ((unsigned char *)s)[6]), \
  366.        (((unsigned char *)d)[7] = ((unsigned char *)s)[7]))
  367.  
  368.  
  369.  
  370. /*
  371. ** Macros for matching character classes.  These are in addition to
  372. ** those provided in <ctypes.h>
  373. */
  374.  
  375. #ifdef  iswhite
  376. # undef iswhite
  377. #endif
  378. #define iswhite(c)      (c == ' ' || c == '\t' || c == '\n')
  379.  
  380. #ifdef  iscompop
  381. # undef iscompop
  382. #endif
  383. #define iscompop(c)     (c == '<' || c == '>' || c == '=')
  384.  
  385.